#include <stdio.h>
#include <iostream>

#ifndef Uint8 
#define Uint8 unsigned char
#endif

#ifndef SDL_Surface 
#define SDL_Surface unsigned int
#endif

using namespace std;

struct Nodo
{
	unsigned int ID;
	unsigned int *surfaceGen;
	unsigned int *surfacePers;

	unsigned int coord_x;
	unsigned int coord_y;

	Nodo* prox;
	Nodo* prev;
};

struct Lista
{
	Nodo* primero;
};

struct Iterador
{
	Nodo *actual;
};

extern "C" void agregar_item_ordenado(Lista* la_lista, SDL_Surface* surfacePers, SDL_Surface* surfaceGen, unsigned int x, unsigned int y, unsigned int ID);
extern "C" void borrar(Lista* la_lista, unsigned int x, unsigned int y);
extern "C"  Lista* constructor_lista();
extern "C" void inicializar_nodo(Nodo* nuevo, SDL_Surface *surfacePers, SDL_Surface *surfaceGen, unsigned int x, unsigned int y, unsigned int ID);
extern "C" void liberar_lista(Lista* l);
extern "C" bool verificar_id (Lista* la_lista, unsigned int id);

void mostrarNodo(Nodo * nodo)
{
	cout << "[(" << nodo->prev << "),(" << nodo << "){" << nodo->ID << ","<< nodo->surfaceGen << "," << nodo->surfacePers << "," << nodo->coord_x << "," << nodo->coord_y << "},("<< nodo->prox << ")]" << endl;	
}

int main(){
	//crear lista vacia
	Lista *lista;
	lista = constructor_lista();
	//cout << "Puntero de la Lista " << lista->primero << endl << endl;
	
	//crear nodo1
	unsigned int Id = 1;
	unsigned int *surfaceGen = NULL;
	unsigned int *surfacePers = NULL;
	unsigned int x = 100;
	unsigned int y = 20;
	Nodo* prox = NULL;
	Nodo* prev = NULL;
	//agrego nodo1 a la lista
	agregar_item_ordenado(lista, surfacePers,surfaceGen, x, y, Id);
	
	//crear nodo2
	unsigned int Id2 = 4;
	unsigned int *surfaceGen2 = NULL;
	unsigned int *surfacePers2 = NULL;
	unsigned int x2 = 100;
	unsigned int y2 = 80;
	//agrego nodo2 a la lista
	agregar_item_ordenado(lista, surfacePers2,surfaceGen2, x2, y2, Id2);
	
	//crear nodo3
	unsigned int Id3 = 11;
	unsigned int *surfaceGen3 = NULL;
	unsigned int *surfacePers3 = NULL;
	unsigned int x3 = 100;
	unsigned int y3 = 80;
	//agrego nodo3 a la lista
	agregar_item_ordenado(lista, surfacePers3,surfaceGen3, x3, y3, Id3);
	
	//creo nodo4
	unsigned int Id4 = 11;
	unsigned int *surfaceGen4 = NULL;
	unsigned int *surfacePers4 = NULL;
	unsigned int x4 = 100;
	unsigned int y4 = 24;
	//agrego nodo4 a la lista
	agregar_item_ordenado(lista, surfacePers4,surfaceGen4, x4, y4, Id4);
	
	//Muestro el contenido de la lista
	cout << "Muestro el contenido de la lista" << endl;
	cout << "Puntero de la Lista " << lista->primero << endl;
	mostrarNodo(lista->primero);
	mostrarNodo(lista->primero->prox);
	mostrarNodo(lista->primero->prox->prox);
	mostrarNodo(lista->primero->prox->prox->prox);
	
	unsigned int x_borrar = 150 ;
	unsigned int y_borrar = 25 ;
	
	cout << "Borrar" << endl;
	borrar(lista, x_borrar, y_borrar);
	
	//Muestro el contenido de la lista
	cout << "Puntero de la Lista " << lista->primero << endl;
	mostrarNodo(lista->primero);
	mostrarNodo(lista->primero->prox);
	
	/*
	cout << "Verificar_id" << endl;
	
	bool ok = 	verificar_id (lista, 0) ;
	bool res = verificar_id (lista, 11) ;
	
	cout << "Ok" << ok << endl;
	cout << "No ok" << res << endl;
	
	
	liberar_lista(lista);
	cout << "Liberar_lista" << endl;
	cout << "Primero:" << lista->primero << endl;	
	*/
	return(0);

}

